#ifndef _STRING_H_
#define _STRING_H_

#include "types.h"


static inline int strcmp_word(const uint8_t *s1, const uint8_t *s2)
{
   uint16_t i = 0;

   while (s1[i] != ' ' && s2[i] != ' ' && s1[i] != 0 && s1[i] == s2[i]) {
       i++;
   }

   if ((s1[i] == ' ' || s1[i] == 0) && (s2[i] == ' ' || s2[i] == 0)) {
       return 0;
   } else {
       return s1[i] - s2[i];
   }
}

static inline int strcmp(const uint8_t *s1, const uint8_t *s2)
{
    uint16_t i = 0;
    while (s1[i] != 0 && s2[i] == s1[i]) {
        i++;
    }

    return s1[i] - s2[i];
}

static inline int strlen(const uint8_t *str)
{
   uint16_t len = 0;
   while(str[len] != 0) { len++; }

   return len;
}

static inline void strcpy(uint8_t *dest, const uint8_t *src)
{
    while (*src) {
        *dest++ = *src++;
    }

    *dest = 0;
    return;
}

static inline void strncpy(uint8_t *dest, const uint8_t *src, uint16_t n)
{
   while (*src && n) {
      *dest++ = *src++;
      n--;
   }

   *dest = 0;
   return;
}

#endif // string.h
